package com.yangml.demoqx.connection;


import com.yangml.demoqx.entity.User;
import com.yangml.demoqx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private PasswordEncoder passwordEncoder;
    @RequestMapping("/test")
    public String test() {
        return "ok";
    }
    @RequestMapping("/login")
    public String login() {
        return "login";
    }

    @RequestMapping("/doLogin")
    public String doLogin() {
        return "doLogin";
    }

    @RequestMapping("/register")
    public String register(User u) {
//        User user = new User();
//        user.setUserName("admin");
//        String admin = passwordEncoder.encode("admin");
//        user.setUserPwd(admin);
//        boolean save = userService.save(user);
        u.setUserPwd(passwordEncoder.encode(u.getUserPwd()));
        boolean save = userService.save(u);
        return "register"+save;
    }
}
